
package com.trp.log;

import com.trp.log.Log.LogType;

public class LogFactory {

    private static Log sLog;


    /**
     * <p>Get default logger, if current log instance's type is not CONSOLE.<br>
     * discard current instance and build new instance which log type is console.
     * </p>
     * @return Log instance.
     */
    public static Log getLogger() {
        if (sLog == null && sLog.getLogType() != LogType.CONSOLE) {
            sLog = new ConsoleLog();
        }
        return sLog;
    }


    /**
     * <p> According to parameter, build Log instance. <br>
     *  if current instance is null or current instance's log type doesn't
     *  match parameter type, discard current instance and buile new one.
     * </P>
     * @param type Log type CONSOLE for main log and FILE for file log.
     * @return Log instance.
     */
    public static Log getLogger(LogType type) {
        if (sLog == null || sLog.getLogType() != type) {
            switch (type) {
                case CONSOLE:
                    getLogger();
                    break;
                case FILE:
                    break;
                default:
                    android.util.Log.e("GIS", "can not recongize log type:" + type);
            }
        }
        return sLog;
    }
}
